package com.aiiter.web.controller.house;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aiiter.house.domain.vo.HouseTenantInformationVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aiiter.common.annotation.Log;
import com.aiiter.common.core.controller.BaseController;
import com.aiiter.common.core.domain.AjaxResult;
import com.aiiter.common.enums.BusinessType;
import com.aiiter.house.domain.HouseTenantInformation;
import com.aiiter.house.service.IHouseTenantInformationService;
import com.aiiter.common.utils.poi.ExcelUtil;
import com.aiiter.common.core.page.TableDataInfo;

/**
 * 存储租户的基本信息及与房间的关联Controller
 * 
 * @author yaocheng
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/house/tenantInformation")
public class HouseTenantInformationController extends BaseController
{
    @Autowired
    private IHouseTenantInformationService houseTenantInformationService;

    /**
     * 查询存储租户的基本信息及与房间的关联列表
     */
    @PreAuthorize("@ss.hasPermi('house:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseTenantInformation houseTenantInformation)
    {
        startPage();
        List<HouseTenantInformation> list = houseTenantInformationService.selectHouseTenantInformationList(houseTenantInformation);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('house:information:list')")
    @GetMapping("/expiredtenantin")
    public AjaxResult expiredtenantinlist( )
    {
        List<HouseTenantInformationVo> list = houseTenantInformationService.selectHouseExpiredTenantInformationList();
        return AjaxResult.success(list);
    }

    @GetMapping("/tree")
    public AjaxResult tree(){
        List<Object> objects = houseTenantInformationService.selectHouseTenantInformationTree();
        return success(objects);
    }
    @GetMapping("/treetext")
    public AjaxResult treetext(){
        List<Object> objects = houseTenantInformationService.selectHouseTenantInformationTreeText();
        return success(objects);
    }


    /**
     * 导出存储租户的基本信息及与房间的关联列表
     */
    @PreAuthorize("@ss.hasPermi('house:information:export')")
    @Log(title = "存储租户的基本信息及与房间的关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseTenantInformation houseTenantInformation)
    {
        List<HouseTenantInformation> list = houseTenantInformationService.selectHouseTenantInformationList(houseTenantInformation);
        ExcelUtil<HouseTenantInformation> util = new ExcelUtil<HouseTenantInformation>(HouseTenantInformation.class);
        util.exportExcel(response, list, "存储租户的基本信息及与房间的关联数据");
    }


    /**
     * 获取存储租户的基本信息及与房间的关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:information:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") Long tenantId)
    {
        return success(houseTenantInformationService.selectHouseTenantInformationByTenantId(tenantId));
    }

    /**
     * 新增存储租户的基本信息及与房间的关联
     */
    @PreAuthorize("@ss.hasPermi('house:information:add')")
    @Log(title = "存储租户的基本信息及与房间的关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseTenantInformation houseTenantInformation)
    {
        return toAjax(houseTenantInformationService.insertHouseTenantInformation(houseTenantInformation));
    }

    /**
     * 修改存储租户的基本信息及与房间的关联
     */
    @PreAuthorize("@ss.hasPermi('house:information:edit')")
    @Log(title = "存储租户的基本信息及与房间的关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseTenantInformation houseTenantInformation)
    {
        return toAjax(houseTenantInformationService.updateHouseTenantInformation(houseTenantInformation));
    }

    /**
     * 删除存储租户的基本信息及与房间的关联
     */
    @PreAuthorize("@ss.hasPermi('house:information:remove')")
    @Log(title = "存储租户的基本信息及与房间的关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable Long[] tenantIds)
    {
        return toAjax(houseTenantInformationService.deleteHouseTenantInformationByTenantIds(tenantIds));
    }
}
